# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                monit
version             5.35.2
revision            1

categories          sysutils
platforms           darwin freebsd linux netbsd openbsd solaris
license             GPL-3
maintainers         nomaintainer

description         Utility for managing and monitoring processes, files etc.
long_description    A utility for managing and monitoring processes, programs, \
                    files, directories and filesystems on a Unix system. Monit \
                    conducts automatic maintenance and repair and can execute \
                    meaningful causal actions in error situations. Monit logs \
                    to syslog or to its own log file and notifies you about error \
                    conditions via customizable alert messages. Monit can perform \
                    various TCP/IP network checks, protocol checks and can utilize \
                    SSL for such checks. Monit provides an optional http(s) interface \
                    and you can use a browser to access the Monit program.

homepage            https://mmonit.com/monit
master_sites        ${homepage}/dist/

checksums           rmd160  1d9dd1a87911e960ac62ef5138f581e9ea199046 \
                    sha256  4dfef54329e63d9772a9e1c36ac99bc41173b79963dc0d8235f2c32f4b9e078f \
                    size    1526704

# Rather use ports on legacy systems:
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    depends_build   port:bison port:flex
} else {
    depends_build   bin:bison:bison bin:flex:flex
}
depends_lib         path:lib/libssl.dylib:openssl port:zlib

patchfiles          patch-monitrc.diff

# https://trac.macports.org/ticket/73279
# Also remove a flag used by Xcode gcc but not accepted by modern one:
# gcc-mp-14: error: unrecognized command-line option '-no-cpp-precomp'
patchfiles-append   patch-configure.diff

# https://trac.macports.org/ticket/73280
patchfiles-append   patch-device-sysdep_DARWIN.c

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/monitrc
}

# ./src/thread/Thread.h:32:23: error: stdatomic.h: No such file or directory
compiler.c_standard 2011

configure.args      --with-ssl-dir=${prefix} --with-zlib=${prefix}

platform freebsd {
    build.type      gnu
}

platform netbsd {
    build.type      gnu
}

platform openbsd {
    build.type      gnu
}

destroot.keepdirs   ${destroot}${prefix}/etc/monit.d
post-destroot {
    xinstall -m 700 ${worksrcpath}/monitrc ${destroot}${prefix}/etc/monitrc

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 444 -W ${worksrcpath} CONTRIBUTORS COPYING \
        ${destroot}${prefix}/share/doc/${name}
}

startupitem.create     yes
startupitem.executable ${prefix}/bin/monit -I -c ${prefix}/etc/monitrc
